package com.aspose.cells;

import java.util.Iterator;

class zjt {
   private Object[] a;
   private int b;
   private int c;

   public zjt(int var1) {
      this.a = new Object[var1];
      this.c();
   }

   public Object a(int var1) {
      return this.a[(this.b + var1) % this.a.length];
   }

   public void a(int var1, Object var2) {
      this.a[(this.b + var1) % this.a.length] = var2;
   }

   public int a() {
      return this.c > this.b ? this.c - this.b : this.a.length - (this.b - this.c);
   }

   public Object b() {
      return this.c > 0 ? this.a[this.c - 1] : (this.b < this.a.length ? this.a[this.a.length - 1] : null);
   }

   public void c() {
      this.b = this.a.length;
      this.c = 0;
   }

   public void a(Object var1) {
      this.a[this.c] = var1;
      if (this.c == this.b) {
         ++this.b;
         if (this.b == this.a.length) {
            this.b = 0;
            this.c = 0;
         } else {
            this.c = this.b;
         }
      } else {
         if (this.b == this.a.length) {
            this.b = 0;
         }

         ++this.c;
         if (this.c == this.a.length) {
            this.c = 0;
         }
      }

   }

   public void b(Object var1) {
      if (var1 != this.b()) {
         int var2;
         if (this.b == this.c) {
            for(var2 = 0; var2 < this.a.length; ++var2) {
               if (this.a[var2] == var1) {
                  if (var2 == this.b) {
                     ++this.b;
                     if (this.b == this.a.length) {
                        this.b = 0;
                     }

                     this.c = this.b;
                  } else if (var2 > this.b) {
                     System.arraycopy(this.a, this.b, this.a, this.b + 1, var2 - this.b);
                     this.a[this.b] = var1;
                     ++this.b;
                     this.c = this.b;
                  } else if (var2 < this.b - 1) {
                     System.arraycopy(this.a, var2 + 1, this.a, var2, this.b - 1 - var2);
                     this.a[this.b - 1] = var1;
                  }

                  return;
               }
            }
         } else if (this.b < this.c) {
            for(var2 = this.b; var2 < this.c; ++var2) {
               if (this.a[var2] == var1) {
                  System.arraycopy(this.a, var2 + 1, this.a, var2, this.c - 1 - var2);
                  this.a[this.c - 1] = var1;
                  return;
               }
            }
         } else {
            for(var2 = 0; var2 < this.c; ++var2) {
               if (this.a[var2] == var1) {
                  System.arraycopy(this.a, var2 + 1, this.a, var2, this.c - 1 - var2);
                  this.a[this.c - 1] = var1;
                  return;
               }
            }

            if (this.a[this.b] == var1) {
               this.a[this.c] = var1;
               ++this.c;
               ++this.b;
               if (this.b == this.a.length) {
                  this.b = 0;
               }

               return;
            }

            for(var2 = this.b + 1; var2 < this.a.length; ++var2) {
               if (this.a[var2] == var1) {
                  this.a[this.c] = var1;
                  ++this.c;
                  System.arraycopy(this.a, this.b, this.a, this.b + 1, var2 - this.b);
                  ++this.b;
                  return;
               }
            }
         }

      }
   }

   public void d() {
      int var1;
      int var2;
      if (this.c > this.b) {
         var1 = this.b;

         for(var2 = this.b; var2 < this.c; ++var2) {
            if (this.a[var2] != null) {
               if (var1 < var2) {
                  this.a[var1] = this.a[var2];
               }

               ++var1;
            }
         }

         if (var1 == this.b) {
            this.c();
         } else {
            this.c = var1;
         }
      } else {
         var1 = this.a.length - 1;

         for(var2 = var1; var2 >= this.b; --var2) {
            if (this.a[var2] != null) {
               if (var1 > var2) {
                  this.a[var1] = this.a[var2];
               }

               --var1;
            }
         }

         this.b = var1 + 1;
         var1 = 0;

         for(var2 = 0; var2 < this.c; ++var2) {
            if (this.a[var2] != null) {
               if (var1 < var2) {
                  this.a[var1] = this.a[var2];
               }

               ++var1;
            }
         }

         this.c = var1;
         if (this.b != this.c) {
            if (this.b == this.a.length) {
               this.b = 0;
            }

            if (this.b == this.c) {
               this.c();
            }
         }
      }

   }

   public Iterator e() {
      return new zjt.za(this);
   }

   private class za implements Iterator {
      private zjt b;
      private int c;
      private boolean d;

      za(zjt var2) {
         this.b = var2;
         this.a();
      }

      public boolean hasNext() {
         --this.c;
         if (this.d) {
            return this.c >= this.b.b;
         } else if (this.c < 0) {
            return this.b.a.length + this.c >= this.b.b;
         } else {
            return true;
         }
      }

      public Object next() {
         return this.c < 0 ? this.b.a[this.b.a.length + this.c] : this.b.a[this.c];
      }

      public void a() {
         this.c = this.b.c;
         this.d = this.b.b == this.b.a.length || this.b.c > this.b.b;
      }

      public void remove() {
         throw new UnsupportedOperationException();
      }
   }
}
